const util = require("../../utils/util.js");
Page({

  data: {
  
  },

  onLoad: function (options) {
    let username = wx.getStorageSync('username');
    this.setData({
      username
    });

    this.history(options)
      .then(this.codeData.bind(this));
  },

  history(o) {
    return new Promise(resolve => {
      wx.request({
        url: 'http://47.107.121.61/user/history',
        data: {
          username: this.data.username,
        },
        method: "GET",
        header: {
          'content-type': 'application/json'
        },
        success: res => {
          const status = res.data.status;
          resolve(res);
        }
      })
    })
  },

  // 处理分析数据
  codeData(res) {
    let data = res.data.test;
    if (data.length === 0) {
      util.alertView("提示", "暂无测试数据请先参加测试", () => { });
    }else {
      let test = [];
      for (let item in data) {
        test.push({
          quesName: data[item].quesName,
          test: JSON.stringify(data[item])
        })
      }

      this.setData({
        test
      })
    }
  },

})